//
//  JBWWelcomeViewController.swift
//  新浪微博
//
//  Created by 季伯文 on 2017/7/3.
//  Copyright © 2017年 bowen. All rights reserved.
//

import UIKit

class JBWWelcomeViewController: UIViewController {

    
    override func loadView() {
        view = bgImageView
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        setupHeadImageViewAnim()
    }
    
    private func setupHeadImageViewAnim() {
        
        headImageView.snp.updateConstraints { (make) in
            make.top.equalTo(view).offset(100)
        }
        
        UIView.animate(withDuration: 1, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            //强制刷新当前界面
            self.view.layoutIfNeeded()
        }) { (_) in
            //设置文字动画
            UIView.animate(withDuration: 0.25, animations: { 
                self.messageLabel.alpha = 1
            }, completion: { (_) in
                NotificationCenter.default.post(name: JBWSWITCHVIEWCONTROLLERNOTI, object: "welcomeVC")
            })
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    private func setupUI(){
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        
        headImageView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
        }
        
        messageLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(headImageView.snp.bottom).offset(20)
        }
    
    }
   //背景图片
    private lazy var bgImageView:UIImageView = UIImageView(named: "ad_background")
        
    //个人头像
    private lazy var headImageView: UIImageView = {
        let img = UIImageView(named: "avatar_default_big")
        img.layer.cornerRadius = 45
        img.clipsToBounds = true
        img.layer.borderWidth = 1
        img.layer.borderColor = JBWThemeColor.cgColor
        img.jbw_setImage(withUrlString: JBWOAuthViewModel.share.userAccountModel?.avatar_large)
        return img
    }()
    //欢迎回来
    private lazy var messageLabel: UILabel = {
        let lab = UILabel(text: "欢迎回来", textColor: UIColor.darkGray, fontSize: JBWBigFontSize)
        lab.textAlignment = .center
        lab.alpha = 0
        return lab
        
    }()
}
